//
//  WeakTimerTarget.m
//  555彩票
//
//  Created by zhoubo on 2017/7/4.
//  Copyright © 2017年 zhoubo. All rights reserved.
//

#import "WeakTimerTarget.h"


@interface WeakTimerTarget()

@property (nonatomic, weak) id aTarget;
@property (nonatomic, assign) SEL aSelector;
@end

@implementation WeakTimerTarget



+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(nullable id)userInfo repeats:(BOOL)yesOrNo {
    
    WeakTimerTarget *target = [[WeakTimerTarget alloc] init];
    // 记录真实回调target
    target.aTarget = aTarget;
    target.aSelector = aSelector;
    
    return [NSTimer scheduledTimerWithTimeInterval:ti target:target selector:@selector(update:) userInfo:userInfo repeats:yesOrNo];
}

- (void)update:(NSTimer *)timer{
    //    NSLog(@"update");
    // 回调控制器的update方法
    
    
    [self.aTarget performSelector:self.aSelector withObject:timer];
    //    self performSelector:<#(SEL)#> withObject:<#(id)#>
}

@end
